<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/12/4
 * Time: 16:40
 */
session_start();
$username=$_REQUEST['username'];
$password=$_REQUEST['password'];

$link=mysqli_connect('localhost','ni','123456') or die(json_encode(array('result'=>'connect database fail')));

mysqli_select_db($link,'ajaxdb') or die(json_encode(array('result'=>'select database fail')));

$sql_select="select password from ys3181msg where username = '$username'";

$res=mysqli_query($link,$sql_select);

if (mysqli_fetch_assoc($res)==null){
    echo json_encode(array('result'=>'username is not exist','username'=>$username));
}else{
    $res=mysqli_query($link,$sql_select);
    while ($rows=mysqli_fetch_assoc($res)){
        if ($rows['password']==$password){
            $_SESSION['username']=$username;
            echo  json_encode(array('result'=>'success','username'=>$username));
        }else{
            echo json_encode(array('result'=>'password is not current'));
        }
    }
}
mysqli_close($link);